package luj.game.robot.internal.instance.boss.command.execute.invoke;

import luj.bean.api.BeanContext;
import luj.bean.api.bean.ImmutableBean;
import luj.game.robot.internal.concurrent.parent.RobotParentActor;
import luj.game.robot.internal.instance.boss.command.map.BossCommandMap;

import java.util.Map;

public class BossExecInvoker {

  public BossExecInvoker(BossCommandMap.Cmd cmd, Map<String, Object> param, RobotParentActor bossActor) {
    _cmd = cmd;
    _param = param;
    _bossActor = bossActor;
  }

  public void invoke() {
    var boss = new CBossImpl();
    boss._bossState = _bossActor.getBossState();

    var ctx = new ContextImpl();
    ctx._param = makeParamObj();
    ctx._boss = boss;

    _cmd.getInstance().onExecute(ctx);
  }

  private Object makeParamObj() {
    BeanContext lujbean = _bossActor.getBossDependency().getLujbean();
    ImmutableBean<?> bean = lujbean.createImmutable(_cmd.getParamType(), _param);

    return bean.getValueInstance();
  }

  private final BossCommandMap.Cmd _cmd;

  private final Map<String, Object> _param;
  private final RobotParentActor _bossActor;
}
